import java.util.ArrayList;
import java.util.List;

/**
 * @author gaopeng
 * @date 2019/12/9 9:48 下午
 */
public class Shallow implements Cloneable {
    private List<String> list = new ArrayList<>(2);

    @Override
    protected Shallow clone() throws CloneNotSupportedException {
        return (Shallow) super.clone();
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    /**
     * 浅拷贝
     * @param args
     * @throws CloneNotSupportedException
     */
    public static void main(String[] args) throws CloneNotSupportedException {
        Shallow shallow = new Shallow();
        shallow.getList().add("zhangsan");
        Shallow clone = shallow.clone();
        clone.getList().add("lisi");
        shallow.getList().forEach(System.out::println);
    }
}
